package com.lb.dao;

import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.lb.bean.Admin;
import com.lb.bean.User;

public class AdminDAOImpl extends HibernateDaoSupport implements AdminDAO {

	@SuppressWarnings("unchecked")
	public Admin findAdminByNameandPassword(String name, String password) {
		List ul=(List) this.getHibernateTemplate().find("from Admin au where au.name=? and au.password=?",new String[] {name,password});
		if(ul!=null&&ul.size()>=1){
			return (Admin)((java.util.List) ul).get(0);
		}
		return null;
	}
	@SuppressWarnings("unchecked")
	public List<User> findAllUser(){
		return this.getHibernateTemplate().find("from User");
	}
	@SuppressWarnings("unchecked")
	public List<User> findUserByUserId(int userId){
		return this.getHibernateTemplate().find("from User u where u.userId=?",userId);
	}
	@SuppressWarnings("unchecked")
	public User findUserByuserId(int userId){
		List ul=this.getHibernateTemplate().find("from User u where u.userId=?",userId);
		if(ul!=null&&ul.size()>=1){
			return (User)((java.util.List) ul).get(0);
		}
		return null;
	}
	public void delete(User user){
		this.getHibernateTemplate().delete(user);
	}
}
